from house_service import *


class HouseView:
    house_service = HouseService()
    id_count = 1

    def main_menu(self):
        """
        显示主菜单
        :return:
        """
        while True:
            print()
            print("房屋出租系统".center(32, "="))
            print("\t\t\t1 新增房源")
            print("\t\t\t2 查找房源")
            print("\t\t\t3 删除房源信息")
            print("\t\t\t4 房屋列表")
            print("\t\t\t5 退出")
            key = input("输入您的选择(1-6): ")
            if key in ["1", "2", "3", "4", "5", "6"]:
                if key == "1":
                    self.add_house()
                elif key == '2':
                    self.find_house()
                elif key == '3':
                    self.del_house()
                elif key == '4':
                    self.house_list()
                elif key == '5':
                    print(5)
                    # if exit_sys():
                    break
            else:
                print("错误输出,请重新输入")

    def house_list(self):
        """
        显示房屋列表
        :return:
        """
        print("房屋列表".center(30, "="))
        print("编号\t\t房主\t\t电话\t\t地址\t\t月租\t\t状态(未出租/已出租)")
        houses = self.house_service.get_house_list()
        for house in houses:
            print(house)
        print("房屋信息显示完毕".center(30, "="))

    def add_house(self):
        """
        添加房屋
        :return:
        """
        print("添加房屋".center(30, "="))
        name = input("姓名: ")
        phone = input("电话: ")
        address = input("地址: ")
        rent = int(input("租金: "))
        status = input("状态: ")
        self.id_count += 1
        new_house = House(self.id_count,name,phone,address,rent,status)
        self.house_service.add_house(new_house)
        print("添加成功")

    def find_house(self):
        find_id = int(input("输入id: "))
        house = self.house_service.find_house(find_id)
        if house:
            print(house)
        else:
            print('不存在')
    def del_house(self):
        del_id = int(input("输入id: "))
        if self.house_service.del_house(del_id):
            print("删除成功")
        else:
            print("不存在")
